/*
* This file is part of QSerialDevice, an open-source cross-platform library
* Copyright (C) 2009  Denis Shienkov
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* Contact Denis Shienkov:
*          e-mail: <scapig2@yandex.ru>
*             ICQ: 321789831
*/

#ifndef SERIALDEVICEENUMERATOR_P_H
#define SERIALDEVICEENUMERATOR_P_H

#include <QtCore/QMap>

#include "serialdeviceenumerator.h"

class SerialInfo
{
public:
    QString m_shortName;
    QString m_systemPath;
    QString m_subSystem;
    QString m_locationInfo;
    QString m_driverName;
    QString m_friendlyName;
    QString m_description;
    QStringList m_hardwareID;
    QString m_vendorID;
    QString m_productID;
    QString m_manufacturer;
    QString m_service;
};

#ifdef Q_OS_WIN
#include <qt_windows.h>
class QWinEventNotifier;
#else
struct udev;
struct udev_monitor;
class QSocketNotifier;
#endif

class SerialDeviceEnumeratorPrivate
{
    Q_DECLARE_PUBLIC(SerialDeviceEnumerator)
public:
            SerialDeviceEnumeratorPrivate();
    virtual ~SerialDeviceEnumeratorPrivate();

    void setEnabled(bool enable);
    bool isEnabled() const;

    void setDeviceName(const QString &name);
    QString name() const;
    QString shortName() const;
    QString systemPath() const;
    QString subSystem() const;
    QString locationInfo() const;
    QString driver() const;
    QString friendlyName() const;
    QString description() const;
    QStringList hardwareID() const;
    QString vendorID() const;
    QString productID() const;
    QString manufacturer() const;
    QString service() const;

    bool isExists() const;
    bool isBusy() const;

    SerialDeviceEnumerator * q_ptr;

    QString m_name;

private:
    QMap<QString, SerialInfo> m_map;
    SerialInfo m_si;
    QMap<QString, SerialInfo> updateInfo() const;
#ifdef Q_OS_WIN
    HANDLE m_eventHandle;
    HKEY m_keyHandle;
    QWinEventNotifier *m_eventNotifier;
#else
    struct udev *udev;
    int udev_socket;
    struct udev_monitor *udev_monitor;
    QSocketNotifier *m_eventNotifier;
#endif
    //
    void _q_processWatcher();
    bool isValid() const;
};

#endif // SERIALDEVICEENUMERATOR_P_H
